clear all
set more off
set matsize 10000
tempfile ubigeo temp

local lista trust_police trust_army trust_church trust_newsp trust_rtv trust_parties trust_regi trust_jury trust_parliament trust_jne trust_onpe
local controls schooling male rural native married head 

use mergedp, clear
egen voted_bn = rowmax(voted_blank voted_null)
recode voted_bn voted_blank voted_null (. = 0) if voted == 0

** LABELS
label var todoAT "Violence Exposure"
label var preescA "(1-6)"
label var primarA "(7-11)"
label var secondA "(12-18)"
label var tertiaA "(19-30)"
label var preescT "(1-6)"
label var primarT "(7-11)"
label var secondT "(12-18)"
label var tertiaT "18-30"
******* Results
drop if vote_matter == .
local lista vote_matter voted voted_blank voted_null voted_bn partN dem_works dem_matters1 gov_demo1 gov_auto1

local r = 1
foreach var in `lista' {
	replace `var' = `var' * 100 if `r' != 6
	reghdfe `var' preescA primarA secondA tertiaA preescT primarT secondT tertiaT `controls', abs(ubigeo1993 ubigeonac1993 i.ubigeo1993#i.ubigeonac1993 i.age i.year i.provid#c.trend) vce(cluster ubigeonac1993) keepsin
	est store reg`r'
	sum `var' if e(sample) == 1
	local y = r(mean)
	sum preescA if e(sample) == 1 & preescA
	local sdpea = r(mean)
	sum primarA if e(sample) == 1 & primarA
	local sdpra = r(mean)
	sum secondA if e(sample) == 1 & secondA
	local sdsea = r(mean)
	sum tertiaA if e(sample) == 1 & tertiaA
	local sdtea = r(mean)
	sum preescT if e(sample) == 1 & preescT
	local sdpet = r(mean)
	sum primarT if e(sample) == 1 & primarT
	local sdprt = r(mean)
	sum secondT if e(sample) == 1 & secondT
	local sdset = r(mean)
	sum tertiaT if e(sample) == 1 & tertiaT
	local sdtet = r(mean)
	local npea`r' = (round(((_b[preescA]) * `sdpea') / `y', 0.0001)) * 100
	local npra`r' = (round(((_b[primarA]) * `sdpra') / `y', 0.0001)) * 100
	local nsea`r' = (round(((_b[secondA]) * `sdsea') / `y', 0.0001)) * 100
	local ntea`r' = (round(((_b[tertiaA]) * `sdtea') / `y', 0.0001)) * 100
	local npet`r' = (round(((_b[preescT]) * `sdpet') / `y', 0.0001)) * 100
	local nprt`r' = (round(((_b[primarT]) * `sdprt') / `y', 0.0001)) * 100
	local nset`r' = (round(((_b[secondT]) * `sdset') / `y', 0.0001)) * 100
	local ntet`r' = (round(((_b[tertiaT]) * `sdtet') / `y', 0.0001)) * 100
	local ++r
}

noisily estout reg* ///
using Table_7_0.tex, style(tex) c(b(fmt(2) star) se(par fmt(2))) ///
	label collabels(, none) eqlabels(none) mlabels(, none) varlabel(_cons " $ Control $ ") starlevel(* .1 ** .05 *** .01) ///
	keep(preescA primarA secondA tertiaA preescT primarT secondT tertiaT) ///
	order(preescA primarA secondA tertiaA preescT primarT secondT tertiaT) ///
	stats(r2 N N_clust, fmt(%9.2f %9.0g) labels(`"$ R ^{2}$"' "Observations" "Clusters")) replace 

texdoc init Table_7.tex, replace
tex \begin{table}[h]
tex \caption{Impact of armed conflict on voting, participation and democratic beliefs}
tex \label{tab:table1}
tex \begin{center}
tex \resizebox{16cm}{!}{
tex \begin{tabular}{lcccccccccc} \hline \hline
tex \\
tex & Voting & \multicolumn{4}{c}{Voted in last elections}& Participation & \multicolumn{2}{c}{Democracy} & \multicolumn{2}{c}{Type of preferred gov.} \\
tex & matters & Yes & ...blank & ...null & ...blank or & organisations & works & matters & Democracy & Autocracy \\
tex &&&&&Null&&&&& \\
tex &(1) &(2) &(3) &(4) &(5) &(6) &(7) &(8) &(9) &(10) \\
tex \hline
tex \input{Table_7_0.tex}
tex &&&&&&&&& \\
tex \multicolumn{8}{l}{\textbf{Effect of 1 s.d. change in conflict measure as \% of mean of dependent variable:}} \\
tex \multicolumn{9}{l}{\emph{Army}} \\
tex (1-6) & `npea1' & `npea2' & `npea3' & `npea4' & `npea5' & `npea6' & `npea7' & `npea8' & `npea9' & `npea10' \\
tex (7-11) & `npra1' & `npra2' & `npra3' & `npra4' & `npra5' & `npra6' & `npra7' & `npra8' & `npra9' & `npra10' \\
tex (12-18) & `nsea1' & `nsea2' & `nsea3' & `nsea4' & `nsea5' & `nsea6' & `nsea7' & `nsea8' & `nsea9' & `nsea10' \\
tex (19-30) & `ntea1' & `ntea2' & `ntea3' & `ntea4' & `ntea5' & `ntea6' & `ntea7' & `ntea8' & `ntea9' & `ntea10' \\
tex \multicolumn{9}{l}{\emph{Terrorist}} \\
tex (1-6) & `npet1' & `npet2' & `npet3' & `npet4' & `npet5' & `npet6' & `npet7' & `npet8' & `npet9' & `npet10' \\
tex (7-11) & `nprt1' & `nprt2' & `nprt3' & `nprt4' & `nprt5' & `nprt6' & `nprt7' & `nprt8' & `nprt9' & `nprt10' \\
tex (12-18) & `nset1' & `nset2' & `nset3' & `nset4' & `nset5' & `nset6' & `nset7' & `nset8' & `nset9' & `nset10' \\
tex (19-30) & `ntet1' & `ntet2' & `ntet3' & `ntet4' & `ntet5' & `ntet6' & `ntet7' & `ntet8' & `ntet9' & `ntet10' \\
tex &&&&&&&&& \\
tex \hline
tex \end{tabular}}
tex \end{center}
tex \end{table}	
	
